﻿using System.Data;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using YiTu.DBUtility;
using tour.szhome.map.DTO;
using TOUR.SZHOME.Entity;

namespace TOUR.SZHOME.DAL
{
    public partial class Landscape_ImageDAL
    {
        /// <summary>
        ///  获取相册列表
        /// </summary>
        /// <param name="JQID"></param>
        /// <returns></returns>
        public static List<AlbumDTO> GetAlbumList(int JQID)
        {
            List<AlbumDTO> list = new List<AlbumDTO>();

            string sql = @"select Landscape_Image.JQID,Landscape.JQMC, count(0) as Total,Landscape.XGT
                            from dbo.Landscape_Image
                            inner join dbo.Landscape on Landscape.JQID = Landscape_Image.JQID ";
            if (JQID != 0)
            {
                sql += " where Landscape_Image.JQID = @JQID ";
            }
            sql += " group by Landscape_Image.JQID,Landscape.JQMC,Landscape.XGT";
            List<SqlParameter> commandParms = new List<SqlParameter>();
            commandParms.Add(SqlHelper.CreateParam("@JQID", SqlDbType.Int, 0, ParameterDirection.Input, JQID));

            using (SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text, sql, commandParms))
            {
                while (reader.Read())
                {
                    list.Add(new AlbumDTO()
                    {
                        XMID = Convert.ToInt32(reader["JQID"]),
                        XMMC = reader["JQMC"].ToString(),
                        Total = Convert.ToInt32(reader["Total"]),
                        XMLBT = reader["XGT"].ToString()
                    });
                }
            }
            return list;
        }

        /// <summary>
        /// 获取景区下面的相册详情
        /// </summary>
        /// <param name="JQID"></param>
        /// <returns></returns>
        public static List<Landscape_ImageEntity> GetListByJQID(int JQID)
        {
            List<Landscape_ImageEntity> list = new List<Landscape_ImageEntity>();
            List<SqlParameter> commandParms = new List<SqlParameter>();
            commandParms.Add(SqlHelper.CreateParam("@JQID", SqlDbType.Int, 0, ParameterDirection.Input, JQID));

            string sql = "select * from Landscape_Image where JQID = @JQID ";
            using (SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text, sql, commandParms))
            {
                while (reader.Read())
                {
                    list.Add(ConvertToEntityFromDataReader(reader));
                }
            }

            return list;
        }
    }
}
